package com.cxq.finalproject.util;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

//衣服表数据库类
public class MyClothHelper extends SQLiteOpenHelper {
    //数据库文件名称
    public static final String DB_NAME = "ClothLone";
    //表名
    public static final String TABLE_NAME = "my_cloth";
    // 名字，价格，尺寸，是否租借，用户id，简介
    public static final String Name = "name";
    public static final String Price = "price";
    public static final String Isload = "island";
    public static final String ClothClass = "ClothClass";
    public static final String LoadUserId = "userId";
    public static final String Introduce = "introduce";
    public static final String Sale = "sale";

    // 调用父类构造器
    public MyClothHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                        int version) {
        super(context, name, factory, version);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        // 调用execSQL方法创建表
        db.execSQL("create table if not exists " + TABLE_NAME +
                " (" + Name + " varchar primary key," + Price +
                " varchar," + Isload + " varchar," + LoadUserId + " varchar," + Introduce
                + " varchar," + Sale + " varchar," +  ClothClass + " varchar)" );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("drop table if exists cloth");
        onCreate(db);
    }

    public void initCloth(SQLiteDatabase db){
        Cursor c = db.query(TABLE_NAME,null,null,null,null,null,null);
        if (c.getCount() <= 0) {
            insertCloth(db,"child_1","19.9","0","童装","-1",
                    "孩子穿了很喜欢，下次一定要多借一点","6");
            insertCloth(db,"child_2","49.9","0","童装","-1",
                    "衣服很干净，就是有点脏","14");
            insertCloth(db,"child_3","31","0","童装","-1",
                    "小清新风格，宝贝穿上了根本脱不下来","6");
            insertCloth(db,"child_4","31","0","童装","-1",
                    "小清新风格，宝贝穿上了根本脱不下来","6");
            insertCloth(db,"child_5","30","0","童装","-1",
                    "30块钱买了不后悔，后悔不会买","10");
            insertCloth(db,"child_6","5","0","童装","-1",
                    "买买买，不买不是人","500");

            insertCloth(db,"femal_3","50","0","女装","-1",
                    "小清新风格，美女都爱穿","6");
            insertCloth(db,"femal_4","59","0","女装","-1",
                    "美女搭配，上下班回头率爆表","10");
            insertCloth(db,"femal_5","88","0","女装","-1",
                    "韩式风格","4");
            insertCloth(db,"femal_6","60","0","女装","-1",
                    "夏天清凉搭配","9");
            insertCloth(db,"femal_7","70","0","女装","-1",
                    "情侣装，男女生心心相印","6");
            insertCloth(db,"femal_8","55","0","女装","-1",
                    "清新学园风格，美好学生时代","11");
            insertCloth(db,"femal_9","33","0","女装","-1",
                    "职场正装","40");
            insertCloth(db,"femal_10","150","0","女装","-1",
                    "新时代美女","3");

            insertCloth(db,"male_1","15","0","男装","-1",
                    "一眼顶针，鉴定为超市里扫货","86");
            insertCloth(db,"male_2","147","0","男装","-1",
                    "西装暴徒，速速来借","3");
            insertCloth(db,"male_3","99","0","男装","-1",
                    "南极的兄弟穿了都中暑啦","6");
            insertCloth(db,"male_4","60","0","男装","-1",
                    "是兄弟就来买我","9");
            insertCloth(db,"male_5","69","0","男装","-1",
                    "北方的兄弟都爱穿","11");
            insertCloth(db,"male_6","66","0","男装","-1",
                    "南方的兄弟都说好","15");
            insertCloth(db,"male_7","60","0","男装","-1",
                    "西装，打领带，做成功人士","5");
            insertCloth(db,"male_8","63","0","男装","-1",
                    "野外钓鱼套装","10");
        }
    }

    public void insertCloth(SQLiteDatabase db , String name, String price, String isload,String clothClass,String loadUserId
    , String introduce, String sale){
        ContentValues values = new ContentValues();
        values.put(Name,name);
        values.put(Price,price);
        values.put(Isload,isload);
        values.put(ClothClass,clothClass);
        values.put(LoadUserId,loadUserId);
        values.put(Introduce,introduce);
        values.put(Sale,sale);
        long rid = db.insert(TABLE_NAME,Name,values);
//        db.close();
    }

}
